package discrete.math;
/**
 * 
 * @author William Larson-Garcia
 * Creates a Matrix and allows it to be filled printed and cleared
 * 
 *
 */

public class MatrixMath {
	private int mrows;
	private int mcolumns;
	public int[] [] lmatrix = new int [21] [21];
	/**
	 * 
	 */
	public MatrixMath(){
		this(0);
	}
	
	public MatrixMath(int x){
		mrows = x + 1;
		mcolumns = x + 1;
	}
/**
 * Automatically Fills Matrix by generating a random value
 * 
 * @param mrows
 * takes in the number of rows that the matrix has
 * 
 * @param mcolumns
 * takes in the number of columns a matrix has
 */
public void autoFill (int mrows, int mcolumns){
	
	for(int j=0; j < mcolumns; j++){
		for(int i=0; i < mrows; i++){	
			if ( j != i && lmatrix[i][j] != 1)
				lmatrix[i][j] = (int)Math.round(Math.random());
			if (lmatrix [i][j] == 1){
				int iSync = i;
				int jSync = j;
				j = iSync;
				i = jSync;
				lmatrix [i][j] = 1;
			}
	}		
		for( int k = 0; k < mcolumns; k++){
			lmatrix[0][k] = 0;
			lmatrix[k][0] = 0;
		}
	}	
}
/**
 * Displays Matrix by Row on to Standard Out
 */
public void printMatrix (){
	
	for(int j=0; j< mcolumns; j++){
		for(int i=0; i < mrows; i++){
			System.out.print( lmatrix [i] [j] + "\t");
		}
		System.out.print("\n");
	}	
}
/**
 * 
 * @param mrows
 * Takes in a row value
 * @param mcolumns
 * Takes in a column value
 * @return
 * Returns a Single Value at a desired location
 */
public int printSingleValue(int mrows, int mcolumns){
	int value = 0;
	
	value = lmatrix [mrows] [mcolumns];
	
	return value;	
}
/**
 * 
 * @param mrows
 * Takes in a row calue
 * @param mcolumns
 * Takes in a column vale
 * @param val
 * Ensures that the value at position row, column is the same as position column, row
 * This keeps the graph nondirected
 */
public void manualFill(int mrows, int mcolumns, int val){
	lmatrix[mrows][mcolumns] = val;
	lmatrix[mcolumns][mrows] = val;
	
}
/**
 * Clears the matrix to all 0 values
 */
public void clearMatrix(){
	for(int i = 1; i < lmatrix.length; i++){
		for(int j = 1; j < lmatrix.length; j++){
		lmatrix[i][j] = 0;
		}
	}
		
		
}
/**
 * gets the number of rows the matrix has
 * @return
 * number of rows
 */
public int getMrows() {
	return mrows;
}
/**
 * sets the number of rows the matrix will have
 * @param mrows
 * sets the rows for this matrix
 */

public void setMrows(int mrows) {
	this.mrows = mrows;
}
/**
 * gets the number of columns that the matrix has
 * @return
 */
public int getMcolumns() {
	return mcolumns;
}
/**
 * sets the number of columns the matrix will have
 * @param mcolumns
 * sets the columns for the matrix
 */
public void setMcolumns(int mcolumns) {
	this.mcolumns = mcolumns;
}
}


